package top.lixunda.ecommerce.server.good.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.business.BaseServiceImpl;
import top.lixunda.ecommerce.server.business.api.entity.vo.ImageUploadTokenVO;
import top.lixunda.ecommerce.server.good.api.entity.db.GoodPictureDO;
import top.lixunda.ecommerce.server.good.mapper.GoodPictureMapper;
import top.lixunda.ecommerce.server.good.service.IGoodPictureService;

import java.util.List;

/**
 * <p>
 * 商品分类图片 服务实现类
 * </p>
 *
 * @author Xumda
 * @since 2019-12-18
 */
@Service
public class GoodPictureServiceImpl extends BaseServiceImpl<GoodPictureMapper, GoodPictureDO> implements IGoodPictureService {

    /**
     * 根据图片id获取图片信息
     *
     * @param id 图片保存的id
     * @return 图片信息
     */
    @Override
    public GoodPictureDO queryById(Integer id) {
        if (ObjectValidators.isEmpty(id)) {
            throw getAppException("图片id不能为空");
        }
        return this.getById(id);
    }

    /**
     * 根据商品id获取图片信息
     *
     * @param id 图片保存的id
     * @return 图片信息
     */
    @Override
    public List<GoodPictureDO> queryByGoodId(Integer id) {
        if (ObjectValidators.isEmpty(id)) {
            throw getAppException("商品id不能为空");
        }
        return this.list(new LambdaQueryWrapper<GoodPictureDO>()
                .eq(GoodPictureDO::getGoodId, id));
    }

    /**
     * 申请上传商品图片的token
     *
     * @return 上传商品图片的token
     */
    @Override
    public ImageUploadTokenVO createUploadToken() {
        return null;
    }

}
